package com.ymj.controller;

import com.ymj.common.R;
import com.ymj.service.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/photo")
public class PhotoController {
    
    @Autowired
    private PhotoService photoService;
    
    @GetMapping("/sizes")
    public R<Map<String, Object>> getPhotoSizes() {
        return R.ok(photoService.getPhotoSizes());
    }
    
    @PostMapping("/process")
    public R<String> processIdPhoto(
        @RequestParam("file") MultipartFile file,
        @RequestParam("size") String size,
        @RequestParam("background") String background,
        @RequestParam(value = "options", required = false) String[] options
    ) {
        try {
            String processedUrl = photoService.processIdPhoto(file, size, background, options);
            return R.ok(processedUrl);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }
    
    @PostMapping("/export-print")
    public R<String> exportPrintFile(
        @RequestParam("processedUrl") String processedUrl,
        @RequestParam("rows") int rows,
        @RequestParam("cols") int cols,
        @RequestParam("size") String size,
        @RequestParam(value = "spacing", defaultValue = "0") int spacing
    ) {
        try {
            String printUrl = photoService.exportPrintFile(processedUrl, rows, cols, size, spacing);
            return R.ok(printUrl);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }
} 